home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-20 | 1.7 KB | 114 lines | [TEXT/MPS ] |
- #include <TString.h>
- #include <memory.h>
- #include <packages.h>
- #include <strings.h>
-
- void *operator new (size_t size)
- {
- return (void *)NewPtr(size);
- }
-
- void operator delete (void * thePtr)
- {
- if (thePtr) DisposPtr((Ptr) thePtr);
- }
-
- CString::CString (char *s)
- {
- len=strlen(s);
- str=new char[len+1];
- strcpy(str, s);
- }
-
- CString::CString (CString& s)
- {
- len=s.len;
- str=new char[len+1];
- strcpy(str, s.str);
- }
-
- CString::CString (CString *s)
- {
- len=s->len;
- str=new char[len+1];
- strcpy(str, s->str);
- }
-
- CString::CString (long theNum)
- {
- char *p = new char[32];
- numtostring(theNum, p);
- len=strlen(p);
- str= new char[len];
- strcpy(str, p);
- delete p;
- }
-
- CString::CString (char *s, char *s1)
- {
- len=strlen(s)+strlen(s1);
- str=new char[len+1];
- strcpy(str, s);
- strcat(str, s1);
- }
-
- CString::CString (const char *s, short theLen)
- {
- len=theLen;
- str=new char[len+1];
- strncpy(str, s, len);
- str[len]=0;
- }
-
- CString::~CString ()
- {
- delete str;
- }
-
- CString operator +(const CString& s1, const CString& s2)
- {
- return CString(s1.str, s2.str);
- }
-
- void CString::operator +=(const CString& s1)
- {
- char *oldstr=str;
-
- len=strlen(str)+strlen(s1.str);
- str=new char[len+1];
- strcpy(str, oldstr);
- strcat(str, s1.str);
- delete oldstr;
- }
-
- CString& CString::operator =( const CString& s1)
- {
- delete str;
-
- len=strlen(s1.str);
- str=new char[len+1];
- strcpy(str, s1.str);
- return *this;
- }
-
- CString::operator char* () {
- char *p = new char[len+1];
- strcpy(p, str);
- return p;
- }
-
- CString::operator StringPtr () {
- char *p = new char[len+1];
- strcpy((char *)p, str);
- c2pstr(p);
- return (StringPtr)p;
- }
-
- CString::operator Handle () {
- Handle p = NewHandle((Size)len+1);
- HLock(p);
- strcpy(*p, str);
- HUnlock(p);
- return p;
- }
-